import loading from '@/components/xuan-loading/xuan-loading.vue'
import cLabel from "@/components/cat-label/cat-label.vue"
import cc from "@/components/cat-label/new_file.vue"
import fromItem from '@/components/from-item/from-item.vue'
import lsjUpload from '@/uni_modules/lsj-upload/components/lsj-upload/lsj-upload.vue';
import {
	log
} from 'util'
export default {
	data() {
		return {
			Inv: 0,

			appliance: null,
			option: {},

			instantly: true, // 选择文件后是否立即自动上传

			// 微信小程序Map对象for循环不显示，所以转成普通数组，不要问为什么，我也不知道
			count: 8,
			list: [],
			fileList: [], //文件
			flagNum: -1,




			// loading样式
			width: '150rpx',
			height: '100rpx',
			shadeShow: false,
			backgroundColor: "transparent",
			themeColor: '#33CCCC',
			// loading样式

			// 详情
			totalData: {
				userId: "",
				userName: "",
				companyId: "",
				companyName: "",
				projectId: "",
				projectName: "",
				recordfiles: null,
				fId: "",
				fProjectid: "",
				fProjectname: "",
				fProjectfullname: "",
				fCompanyid: "",
				fCompanyname: "",
				fCompanyfullname: "",
				fCreateuserid: "",
				fCreateusername: "",
				fCreatedate: null,
				fModifyuserid: "",
				fModifydate: null,
				fModifyusername: "",
				fIssueunit: "", //下发指令单位
				fUnittype: "", //单位类型
				fOrdernumber: "", //工作指令编号
				fStartcheckdate: null,
				fStartcheckdates: "", //开始检查日期
				fEndcheckdate: null,
				fEndcheckdates: "", //检查日期结束
				fCheckunit: "", //受检单位1
				fCheckunitid: "", //受检单位id1
				fCheckunit2: "", //受检单位2
				fCheckunit2id: "", //受检单位id2
				fCheckproject: "", //受检项目
				fCheckprojectid: "", //受检项目id
				fProblemdescription: "", //存在的问题概述
				fChangerequirements: "", //整改措施及要求
				fRequesttermdate: null,
				fRequesttermdates: "", //要求整改期限
				fFileurl: "", //附件资料
				fCheckdepartment: "", //检查部门
				fCheckinspectors: "", //检查人员姓名
				fSubsignid1: "", //指定签收人1id
				fSubsignname1: "", //指定签收人1姓名
				// fSubsignid2: "", //指定签收人2id
				// fSubsignname2: "", //指定签收人2姓名
				fCcpeople: "", //抄送人姓名
				fCcpeopleid: "", //抄送人id
				// fCcpeople2: "", //抄送人2姓名
				// fCcpeopleid2: "", //抄送人2id
				fReportid: "", //填报人id'
				fReportname: "", //填报人姓名
				fReportdate: null,
				fReportdates: "", //填报时间
				fSignunit1: "", //受检单位1 签收单位
				fSigndescription1: "", //受检单位1 签收说明
				fSignid1: "", //受检单位1 签收人id
				fSignname1: "", //受检单位1 签收人姓名
				fSigndate1s: "", //受检单位1 签收时间
				// fSignunit2: "", //受检单位2 签收单位
				// fSigndescription2: "", //受检单位2 签收说明
				// fSignid2: "", //受检单位2 签收人id
				// fSignname2: "", //受检单位2 签收人姓名
				// fSigndate2s: "", //受检单位2 签收时间
				fRecheckresult1: "", //受检单位1 复查结果
				fFilenumber1: "", //受检单位1 复查文件编号
				fRecheckdescription1: "", //受检单位1  复查情况说明
				fRecheckfile1: "", //受检单位1 复查相关资料
				fRecheckid1: "", //受检单位1 复查人id
				fRecheckname1: "", //受检单位1 复查人姓名
				fRecheckdate1s: "", //受检单位1 复查完成时间
				// fRecheckresult2: "", //受检单位2 复查结果
				// fFilenumber2: "", //受检单位2 复查文件编号
				// fRecheckdescription2: "", //受检单位2  复查情况说明
				// fRecheckfile2: "", //受检单位2 复查相关资料
				// fRecheckid2: "", //受检单位2 复查人id
				// fRecheckname2: "", //受检单位2 复查人姓名
				// fRecheckdate2s: "", //受检单位2 复查完成时间
				fStatus: "", //信息状态
				fIsdeleted: "",
			},
			userInfo: null,
			must: "must",
			disabled: false,
			recordfiles: [], //删除文件集合
			options: null, //上个页面传递过来的参数
			timing: null, //当前年月日
			//显示隐藏
			basic: 1, //基本信息
			consumption: 1, //材料用量
			close: 1, //闭合申请单
			auditA: 1, //一级审核
			auditB: 1, //二级审核
			//显示隐藏
		};
	},

	onReady() {
		this.$nextTick(() => {
			this.$refs.lsjUpload.show();
		})
		this.fileList = [];
	},
	onLoad(options) {
		var that = this;
		uni.getStorage({ //监督检查方式
			key: 'userInfo',
			success: function(res) {
				that.userInfo = JSON.parse(res.data);

			}
		});

		that.fileList = [];
		that.options = options;
		that.getDetailData(options.fid);
		// || MP-WEIXIN || H5
		// #ifdef APP-PLUS
		this.playVideo()
		uni.$on('drawer-page', (data) => {
			that.clickNum(data)
		})
		// #endif
		// #ifdef H5
		this.appliance = 1
		// #endif

	},
	onShow() {

	},
	components: {
		loading,
		cLabel,
		lsjUpload,
		cc,
		fromItem
	},

	onUnload() {
		uni.$off('drawer-page')
	},

	methods: {
		submit() {
			var that = this
			this.Inv = 1

		},
		unsubmit() {
			var that = this
			this.Inv = 0
		},

		//显示隐藏
		downUp(num) {
			if (num == 1) {
				this.basic = 2;
			} else {
				this.basic = 1;
			}
		},
		downUpConsumption(num) {
			if (num == 1) {
				this.consumption = 2;
			} else {
				this.consumption = 1;
			}
		},

		downUpClose(num) {
			if (num == 1) {
				this.close = 2;
			} else {
				this.close = 1;
			}
		},
		downUpAuditA(num) {
			if (num == 1) {
				this.auditA = 2;
			} else {
				this.auditA = 1;
			}
		},
		downUpAuditB(num) {
			if (num == 1) {
				this.auditB = 2;
			} else {
				this.auditB = 1;
			}
		},
		//显示隐藏


		pdfPage(name, url) {
			console.log("打开文件", name, url);
			// 文件预览
			let links = encodeURIComponent(url)

			uni.navigateTo({
				url: '/pages/apply/pdf?links=' + links + +"&" + "names=" + name
			});
		},
		fpersonnameShow() {
			this.$refs.tkitree._show();
		},
		// 上传进度回调
		onprogress(item) {
			if (item.responseText) {
				var data = JSON.parse(item.responseText)
				var url = data[0].atta.fFilepath
				var urlPath;
				if (url.indexOf("D:") != -1) {
					urlPath = url.replace(/D:/, "http://1.14.19.236:8301")
				}
				this.fileList.push({
					url: urlPath,
					name: item.name,
					fId: data[0].atta.fId
				});

			}

		},
		// 文件选择回调
		onChange(files) {
			
		},



		clickNum(data) {
			if (data == 0) {
				this.saveData(data)
			}
		},



		getDetailData(id) {
			this.getDate();
			var that = this;
			that.fileList = [];
			var datas = {
				fId: id,
			}
			that.$http.getWorkOrderExecutionReport2ByFid(datas).then(res => {
				if (res.errcode == 0) {
					console.log(res.data.yjQmpMsWrokorderExecutionreport2)
					that.totalData = res.data.yjQmpMsWrokorderExecutionreport2;
					// 签收单位1
					if (
						this.totalData.fSignunit1 == "" ||
						this.totalData.fSignunit1 == null
					) {
						this.totalData.fSignunit1 = this.userInfo.companyName;
					}
					// 签收人1
					if (
						this.totalData.fSignid1 == "" ||
						this.totalData.fSignid1 == null ||
						this.totalData.fSignname1 == "" ||
						this.totalData.fSignname1 == null
					) {
						this.totalData.fSignname1 = this.userInfo.realName;
						this.totalData.fSignid1 = this.userInfo.userId;
					}
					// 签收时间1
					if (
						this.totalData.fSigndate1s == "" ||
						this.totalData.fSigndate1s == null
					) {
						this.totalData.fSigndate1s = this.timing;
					}




					// 文件
					var file = res.data.fFileurllist;
					file.map((item, index) => {
						that.fileList.push({
							fId: item.fId,
							name: item.fFileName,
							url: item.url
						})
					})
					that.page = true


				} else {
					uni.showToast({
						title: "请求失败",
						icon: 'none',
						duration: 2000
					});
				}

			}, (err) => {
				uni.showToast({
					title: "接口报错",
					icon: 'none',
					duration: 2000
				});
			})

		},

		// 判断必填项
		saveData(data) {

			var that = this;
			if (that.totalData.fSignunit1 == "" || that.totalData.fSignunit1 == undefined) {
				uni.showToast({
					title: '受检单位签收 签收单位不能为空',
					icon: 'none',
					duration: 2000
				});
				return false;
			} else if (that.totalData.fSignname1 == "" || that.totalData.fSignname1 ==
				undefined) {
				uni.showToast({
					title: '受检单位签收 签收人不能为空',
					icon: 'none',
					duration: 2000
				});
				return false;
			} else if (that.totalData.fSigndate1s == "" || that.totalData.fSigndate1s ==
				undefined) {
				uni.showToast({
					title: '受检单位签收 签收日期不能为空',
					icon: 'none',
					duration: 2000
				});
				return false;
			} else {
				let totalData1 = {
					fId: that.totalData.fId, //当前fid
					fSignunit1: this.totalData.fSignunit1, //受检单位1 签收单位
					fSigndescription1: this.totalData.fSigndescription1, //受检单位1 签收说明
					fSignid1: this.totalData.fSignid1, //受检单位1 签收人id
					fSignname1: this.totalData.fSignname1, //受检单位1 签收人姓名
					fSigndate1s: this.totalData.fSigndate1s, //受检单位1 签收时间
					userId: that.userInfo.userId, // 当前登录人id
					userName: that.userInfo.realName, // 当前登录人姓名
				};
				that.$refs.loading.open();
				this.$http.saveWorkOrderExecutionReport2BySign1(totalData1).then(res => {
					if (res.errcode == 0) {
						uni.showToast({
							title: "保存成功",
							icon: 'none',
							duration: 2000
						})
						uni.navigateTo({
							url: '/pages/apply/scene/distribute/testing/index'
						});
						this.$refs.loading.close();
					} else {
						uni.showToast({
							title: "保存失败",
							icon: 'none',
							duration: 2000
						});
						this.$refs.loading.close();
					}
				}, (err) => {
					uni.showToast({
						title: "请求失败",
						icon: 'none',
						duration: 2000
					});
					this.$refs.loading.close();
				})

			}
		},

		// 原生窗体按钮显示
		playVideo() {
			let subNVue = uni.getSubNVueById('safe_notice')
			subNVue.show()
		},

		// 获取当前日期
		getDate() {
			var time = new Date();
			const y = time.getFullYear();
			const m = (time.getMonth() + 1 + "").padStart(2, "0");
			const d = (time.getDate() + "").padStart(2, "0");
			const hh = (time.getHours() + "").padStart(2, "0");
			const mm = (time.getMinutes() + "").padStart(2, "0");
			const ss = (time.getSeconds() + "").padStart(2, "0");
			// var timer = `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
			var timer = `${y}-${m}-${d} ${hh}:${mm}`;
			var timing = `${y}-${m}-${d}`;
			this.timing = `${y}-${m}-${d}`;
			this.time = `${hh}:${mm}`;
			this.lasttiming = `${y}-${m}-${d}`;
			this.lasttime = `${hh}:${mm}`;

		},
		callback() {}
	}
}
